import time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

from Common.Unity import ForumDriver


class TestEdit:
    url:""
    driver:""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)

    def TestEdit(self):
        #先点击首页
        self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a > span.nav-link-title").click()
        #首先先点击进入编辑界面
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        #输入标题
        title_label=self.driver.find_element(By.CSS_SELECTOR,"#article_post_title")
        title_label.send_keys("这是一个自动化测试")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element

        # 正常输入内容
        ele.send_keys("这是一个自动化测试用例")
        time.sleep(2)
        #点击发布
        a=self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit")
        self.driver.execute_script("arguments[0].click();", a)
        print("编辑页面测试成功")


